package com.wise.service.local.content.code;

import com.wise.model.content.utils.SetCode2Cache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.concurrent.TimeUnit;

@Service
@SummerService
public class SetCode2CacheService implements SummerServiceBean<SetCode2Cache> {

    @Value("${app.code-life-time}")
    private int codeLifeTime;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public void sum(SetCode2Cache summer) {

        ValueOperations<String, String> opt = redisTemplate.opsForValue();
        opt.set(summer.getKey(), summer.getValue(), codeLifeTime, TimeUnit.SECONDS);

    }
}
